<template>
  <div>
    <!-- 幻灯片 开始 -->
    <!-- 轮播图 -->
    <div class="Rotation">
       <!-- <client-only> 这个组件时用对[Vue warn]: The client-side rendered virtual DOM tree -->
      <div class="header-swiper" >
        <client-only>
        <swiper ref="mySwiper" :options="swiperOption">

          <swiper-slide v-for="banner in bannerList" :key="banner.id">
             
            <a target="_blank" href="/">
              <img :src="banner.imageUrl" />
            </a>       
          </swiper-slide>  
          <!-- 分页器 -->
          <div class="swiper-pagination" slot="pagination"></div>

          <!-- 前进后退按钮 -->

          <div class="swiper-button-next" slot="pagination">
            <img src="~/assets/img/s-next-btn.png" />
          </div>
          <div class="swiper-button-prev" slot="pagination">
            <img src="~/assets/img/s-prev-btn.png" />
          </div>
        </swiper>
        </client-only>
        
      </div>
    </div>
    <!-- 轮播图 -->

    <!-- 幻灯片 结束 -->
    <div id="aCoursesList">
      <!-- 网校课程 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">热门课程</span>
            </h2>
          </header>
          <div>
            <article class="comm-course-list">
              <ul class="of" id="bna" >
                <li v-for="course in eduList" :key="course.id">
                  <div class="cc-l-wrap">
                    <section class="course-img">
                      <img
                         :src="course.cover"
                        class="img-responsive"
                        :alt="course.title"
                      />
                      <div class="cc-mask">
                        <a href="#" title="开始学习" class="comm-btn c-btn-1"
                          >开始 学习</a
                        >
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a
                        href="#"
                        :title="course.title"
                        class="course-title fsize18 c- 333"
                        >{{course.title}}</a
                      >
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fr jgTag bg-green" v-if="Number(course.price) === 0">
                        <i class="c-fff fsize12 f-fA" >免费</i>
                      </span>
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA">9634人学习</i>
                        |
                        <i class="c-999 f-fA">9634评论</i>
                      </span>
                    </section>
                  </div>
                </li>
                     
                
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="#" title="全部课程" class="comm-btn c-btn-2">全部课程</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校课程 结束 -->
      <!-- 网校名师 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">名师大咖</span>
            </h2>
          </header>
          <div>
            <article class="i-teacher-list">
              <ul class="of">
                <li v-for="teacher in teacherList" :key="teacher.id">
                  <section class="i-teach-wrap">
                    <div class="i-teach-pic">
                      <a href="/teacher/1" :title="teacher.name">
                        <img
                          :alt="teacher.name"
                          :src="teacher.avatar"
                        />
                      </a>
                    </div>
                    <div class="mt10 hLh30 txtOf tac">
                      <a href="/teacher/1" :title="teacher.name" class="fsize18 c-666"
                        >{{teacher.name}}</a
                      >
                    </div>
                    <div class="hLh30 txtOf tac">
                      <span class="fsize14 c-999"
                        >{{teacher.career}}</span
                      >
                    </div>
                    <div class="mt15 i-q-txt">
                      <p class="c-999 f-fA">
                        {{teacher.intro}}
                      </p>
                    </div>
                  </section>
                </li>
                
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="#" title="全部讲师" class="comm-btn c-btn-2">全部讲师</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校名师 结束 -->
    </div>
  </div>
</template>
<script>

import banner from '@/api/banner'
import index from '@/api/index'
export default {
  data() {
    return {
      swiperOption: { //轮播图属性设置
        slidesPerView: 3,
        spaceBetween: 10,
        centeredSlides: true,
        on: {
            init() {
                // 初始化设置为第一个
                this.setTranslate(0)
            },
            transitionStart() {
                // 如果是第一张或者第二张就不居中
                if (this.activeIndex == 0 || this.activeIndex == 1 ) {
                    this.setTranslate(1)
                }
                // 最后一张或者两张不动
                if (this.activeIndex == this.slides.length - 2 || this.activeIndex == this.slides.length - 1) {
                    let slideW = (this.width / 5).toFixed(5) //每个轮播的宽度
                    let keepW = slideW * (this.slides.length - 5) //需要设置的setTranslate的宽度
                    this.setTranslate(-keepW)
                }
            }
        },

        loop: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
        autoplay: {
          delay: 2000, //3秒切换一次
          pauseOnMouseEnter: true, //悬停停止切换
        }
      },
      bannerList:{}, //轮播图集合
      eduList:{},
      teacherList:{},

    };
  },
  created() {
    //调用查询banner的方法
    this.getBannerList()
   
    //调用查询热门课程和名师的方法
    this.getHotCourseTeacher()
  },
  methods:{
    //查询banner数据
    getBannerList(){
      banner.getListBanner()
        .then(response => {
          this.bannerList = response.data.Banners
         
        })
    },
    //查询热门课程和名师
    getHotCourseTeacher() {
      index.getIndexData()
        .then(response => {
          this.eduList = response.data.eduList
          this.teacherList = response.data.teacherList
        })
    }
    }
}
</script>

<style>
/* 轮播图 */
.swiper-container {
  width: 100%;
  height: 350px;
}
.swiper-slide {
  /* width: 50% !important; */
  text-align: center;
  font-size: 18px;
  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  transition: 300ms;
  transform: scale(1);
}
.swiper-slide-active,
.swiper-slide-duplicate-active {
  transform: scale(1.5);
  z-index: 9;
}

.swiper-slide img {
  width: 100%;
}

.swiper-button-prev {
  left: 30px;
  right: auto;
}

.swiper-button-prev:after {
  content: "none";
}

.swiper-button-next {
  right: 30px;
  left: auto;
}

.swiper-button-next:after {
  content: "none";
}
/* 轮播图 */
</style>